﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Account_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);

    }

    protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e)
    {
        DBDataContext db = new DBDataContext();
        User CurUser = db.Users.FirstOrDefault(x => x.Username == LoginUser.UserName && x.Password == LoginUser.Password);
        if (CurUser != null)
        {
            FormsAuthentication.RedirectFromLoginPage(LoginUser.UserName, true);
            if (CurUser.Type == "Admin")
            {
                Response.Redirect("/Grander/About.aspx");
            }
            else
            {
                Response.Redirect("/Grander/Contact.aspx");
            }
        }

    }
}
